package com.example.springmvc.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;
import java.util.Optional;

/**
 * @author luo
 * @description
 * @since 2022/8/12 16:35
 */
@RestController
@Slf4j
public class HelloController {


    /**
     * 自定义数据绑定
     * 仅在本controller 中的所有方法内有效
     * @param webDataBinder
     */
    @InitBinder
    public void bind(WebDataBinder webDataBinder){

        SimpleDateFormat format = new SimpleDateFormat("yy-MM-dd");
        CustomDateEditor customDateEditor = new CustomDateEditor(format, true);
        webDataBinder.registerCustomEditor(Date.class,customDateEditor);
    }

    @GetMapping("/hello")
    public Object hello(Date date){
        log.info("进入");
        return "你好："+date;


    }
}
